//
//  YDYYDYMainTabbar.m
//  DY_Weibo3
//
//  Created by 杨德勇 on 2016/8/17.
//  Copyright © 2016年 杨德勇. All rights reserved.
//

#import "YDYMainTabbar.h"
@interface YDYMainTabbar()


@end
@implementation YDYMainTabbar

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupUI];
    }
    return self;
}
-(void)layoutSubviews{
    [super layoutSubviews];
    CGFloat btnW = self.bounds.size.width / 5.0 ;
    CGFloat btnH = self.bounds.size.height;
    CGRect rect = CGRectMake(0, 0, btnW, btnH);
    
    int i = 0;
    for (UIView *subview in self.subviews) {
        
        if ([subview isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
            subview.frame = CGRectOffset(rect, btnW * i, 0);
            i += (i == 1?2:1);
        }
        
    }
    //设置composebtn的位置
    self.composeBtn.frame = CGRectOffset(rect, btnW * 2, 0);
    [self bringSubviewToFront:self.composeBtn];
    
}

-(void)setupUI{
    self.tintColor = [UIColor orangeColor];
    [self addSubview:self.composeBtn];
}

#pragma mark -
#pragma mark -懒加载
-(UIButton *)composeBtn{
    if (_composeBtn == nil) {
       UIButton *btn = [[UIButton alloc] init];
        [btn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"] forState:UIControlStateNormal];
        [btn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button_highlighted"] forState:UIControlStateHighlighted];
        [btn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add"] forState:UIControlStateNormal];
        [btn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add_highlighted"] forState:UIControlStateHighlighted];
        [btn sizeToFit];
        _composeBtn = btn;
        
    }
    return _composeBtn;
}
@end
